/**
 * 2011-11-14下午11:57:58
 */
package dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import util.MysqlConn;
import bean.Goods;

/**
 * @author Baicai 根据id查询一条商品信息
 */
public class SelectOneGoods {

	/**
	 * 根据id查询商品信息
	 * 
	 * @param i
	 * @return Goods
	 */
	public static Goods getOneGoods(int i) {
		try {
			Goods goods = new Goods();
			MysqlConn.setSqlString("select * from goods where goods_id='" + i
					+ "'");// 设置字符串
			ResultSet resultSet = MysqlConn.queryDB();// 执行，获取数据集
			resultSet.next();

			goods.setGoodsId(i);// 取出放入对象里
			goods.setGoodsName(resultSet.getString("goods_name"));
			goods.setGoodsState(Integer.parseInt(resultSet
					.getString("goods_state")));
			goods.setGoodsSort(resultSet.getString("goods_sort"));
			goods.setGoodsPrice(Float.valueOf(resultSet
					.getString("goods_price")));

			goods.setGoodsDate(resultSet.getString("goods_date"));
			goods.setGoodsTime(resultSet.getString("goods_time"));

			goods.setGoodsPicture(resultSet.getString("goods_picture"));
			goods.setGoodsInformation(resultSet.getString("goods_information"));
			goods.setUserId(Integer.parseInt(resultSet.getString("user_id")));

			return goods;

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			MysqlConn.free();
		}

		return null;
	}

}
